package com.snail.snailvr.widget;

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import android.util.AttributeSet;

import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.snail.snailvr.R;
import com.snail.snailvr.VRApp;
import com.snailgame.fastdev.view.SimpleImageView;

/**
 * Created by xixh on 2015/11/2.
 */
public class FSSimpleImageView extends SimpleImageView {
    public FSSimpleImageView(Context context, GenericDraweeHierarchy hierarchy) {
        super(context, hierarchy);
    }

    public FSSimpleImageView(Context context) {
        super(context);

    }

    public FSSimpleImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public FSSimpleImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public FSSimpleImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public FSSimpleImageView(Context context, boolean hasOveylay) {
        super(context);
        if (hasOveylay)
            getHierarchy().setControllerOverlay(VRApp.getContext().getResources().getDrawable(R.drawable.overlay_selector));
    }

    public void setImagePlaceHolder(int resId){
        GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(getResources());
        GenericDraweeHierarchy hierarchy = builder.setFadeDuration(300)
                .setPlaceholderImage(VRApp.getInstance().getResources().getDrawable(resId))
                .build();
        setHierarchy(hierarchy);
    }

    /**
     * 图片加载Uri解析
     *
     * @param uriString
     * @return
     */
    public Uri UriParse(String uriString) {
        if (TextUtils.isEmpty(uriString))
            uriString = "default_img_url_null";
        return Uri.parse(uriString);
    }

    /**
     * Sets a new placeholder drawable
     */
    public void setPlaceHolderImage() {
        setPlaceHolderImageRes(R.drawable.pic_ragle_loading);
    }


    /**
     * Sets a new Overlay drawable and placeholder drawable.
     */
    public void setControllerOverlayAndPlaceHolder() {
        setControllerOverlayAndPlaceHolderRes(R.drawable.ab_btn_selector, R.drawable.pic_ragle_loading);
    }

}
